import request from '../../utils/request.js'
// pages/search/search.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    searchGoods: [],
    isFous: false,
    inputValut: ''
  },
  timeId: null,

  handleInput(e) {
    //console.log(e);
    let value = e.detail.value
    this.setData({
      isFocus: true
    })
    clearTimeout(this.timeId)
    this.timeId = setTimeout(() => {
      this.searchGoods(value)
    }, 1000)
  },
  async searchGoods(value) {
    const res = await request({ url: '/goods/search?query=' + value })
    console.log(res)
    this.setData({
      searchGoods: res.data.message.goods
    })
  },
  handleCancel() {
    this.setData({
      inputValue: '',
      isFocus: false,
      searchGoods: []
    })
  }
})
